import { RemoveReadonly } from "@/utils/types";
import { FormItemGiProps, PopoverPlacement } from "naive-ui";
import { ZIconName } from "../Icon";
import components from "./components/index";

export interface ZFormItemSchema extends RemoveReadonly<FormItemGiProps> {
  label: string;
  path: string;
  /**
   * how many cols(between 0 and ${formItemGridCols}) one item takes.
   * Fill the whole line by default. Extended definition from Naive-UI.
   */
  span?: string | number;
  component?: ZFormItemComponent;
  /* default ${value} */
  componentModelValue?: string;
  componentProps?: Record<any, any>;
  defaultValue?: any;
  /* extra infos for the item field. */
  description?: string | string[];
  descriptionPlacement?: PopoverPlacement;
  descriptionTriggerIcon?: ZIconName;
}

export type ZFormItemComponent = keyof typeof components;

export interface ZFormMethods {
  validate: () => Promise<any>;
  setFields: (values: any) => void;
  resetFields: () => void;
  getFieldsValue: () => any;
}
